<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="机构名称">
              <j-select-depart
                v-model="queryParam.companyId"
                :trigger-change="true"
                customReturnField="id"
                :multi="false"
              ></j-select-depart>
            </a-form-item>
          </a-col>
          <!--          <a-col :md="6" :sm="8">-->
          <!--            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">-->
          <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
          <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">清除条件</a-button>
          <!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
          <!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
          <!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
          <!--              </a>-->
          <!--            </span>-->
          <!--          </a-col>-->
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <!--    <div class="table-operator">-->
    <!--      <a-button @click="handleAdd('临时审计计划制定-新增')" type="primary" icon="plus">新增</a-button>-->
    <!--    </div>-->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="rowIndex"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :pagination="false"
        :scroll="{ x: 'auto', y: 600 }"
      >
        <template slot="companyName" slot-scope="companyName">
          <div style="width: 100%; height: 45px; overflow-x: hidden; overflow-y: auto">{{ companyName }}</div>
        </template>
      </a-table>
    </div>
    <!-- table区域-end -->
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'
import columns from './indexColumns'

export default {
  name: '审计机构报表',
  mixins: [JeecgListMixin],
  components: {},
  data() {
    return {
      queryParam: {},
      // 表头
      columns: columns(this),
      url: {
        list: '/sjzyzhgl/sjAuditOrg/queryOrg',
      },
    }
  },
  methods: {
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() // 查询条件
      this.loading = true
      // this.dataSource=[]
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          let data = res.result.records || res.result
          this.dataSource = data.length && this.accountSum(data)
          if (res.result.total) {
            this.ipagination.total = res.result.total
          } else {
            this.ipagination.total = 0
          }
          // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    // 计算合计
    accountSum(data) {
      let objKeys = Object.keys(data[0])
      let objSum = {}
      for (let i = 0; i < objKeys.length; i++) {
        if (objKeys[i] == 'companyName') {
          objSum[objKeys[i]] = '合计'
        } else if (data[0][objKeys[i]]) {
          objSum[objKeys[i]] = 0
        } else {
          objSum[objKeys[i]] = null
        }
      }
      data.map((item) => {
        for (let i = 0; i < objKeys.length; i++) {
          if (objKeys[i] !== 'companyName' && item[objKeys[i]]) objSum[objKeys[i]] += Number(item[objKeys[i]])
        }
      })
      data.push(objSum)
      return data
    },
  },
}
</script>

<style scoped>
</style>